package com.zy.openchat.core.model.circle;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.zy.openchat.core.model.user.UserInfo;

public class BlogUserDateInfo implements Parcelable {
    @SerializedName(value = "@type")
    public String type;
    public long user_id;
    public long date;


    public boolean isMessageEqual(BlogUserDateInfo dateInfo){
        if(dateInfo==null){
            return false;
        }
        return dateInfo.user_id == user_id;
    }

    public boolean isAvaterDownloaded = false;

    public boolean isAvaterDownloadEqual(BlogUserDateInfo fullInfo){
        if(fullInfo==null){
            return false;
        }
        UserInfo oldUserInfo = UserInfo.getUserInfo(user_id);
        UserInfo newUserInfo = UserInfo.getUserInfo(fullInfo.user_id);
        if(oldUserInfo==null&&newUserInfo==null){
            return true;
        }
        if(oldUserInfo==null||newUserInfo==null){
            return false;
        }
        boolean newIsAvaterDownloaded = false;
        if(newUserInfo.profile_photo!=null&&newUserInfo.profile_photo.isSmallPhotoDownloaded()){
            newIsAvaterDownloaded = true;
        }
        return newIsAvaterDownloaded == isAvaterDownloaded;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.type);
        dest.writeLong(this.user_id);
        dest.writeLong(this.date);
    }

    public void readFromParcel(Parcel source) {
        this.type = source.readString();
        this.user_id = source.readLong();
        this.date = source.readLong();
    }

    public BlogUserDateInfo() {
    }

    protected BlogUserDateInfo(Parcel in) {
        this.type = in.readString();
        this.user_id = in.readLong();
        this.date = in.readLong();
    }

    public static final Creator<BlogUserDateInfo> CREATOR = new Creator<BlogUserDateInfo>() {
        @Override
        public BlogUserDateInfo createFromParcel(Parcel source) {
            return new BlogUserDateInfo(source);
        }

        @Override
        public BlogUserDateInfo[] newArray(int size) {
            return new BlogUserDateInfo[size];
        }
    };
}
